import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["key", "name"];
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { DownOutlined, EllipsisOutlined } from '@ant-design/icons';
import { Button, ConfigProvider, Dropdown, Menu } from 'antd-v4';
import classnames from 'classnames';
import { useContext } from 'react';
import './index.less';
/**
 * 一个简单的下拉菜单
 *
 * @param param0
 */

var DropdownButton = function DropdownButton(_ref) {
  var children = _ref.children,
      menus = _ref.menus,
      onSelect = _ref.onSelect,
      className = _ref.className,
      style = _ref.style;

  var _useContext = useContext(ConfigProvider.ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  var tempClassName = getPrefixCls('pro-table-dropdown');

  var menu = _jsx(Menu, {
    onClick: function onClick(params) {
      return onSelect && onSelect(params.key);
    },
    children: menus === null || menus === void 0 ? void 0 : menus.map(function (item) {
      return _jsx(Menu.Item, {
        children: item.name
      }, item.key);
    })
  });

  return _jsx(Dropdown, {
    overlay: menu,
    className: classnames(tempClassName, className),
    children: _jsxs(Button, {
      style: style,
      children: [children, " ", _jsx(DownOutlined, {})]
    })
  });
};

var TableDropdown = function TableDropdown(_ref2) {
  var propsClassName = _ref2.className,
      style = _ref2.style,
      onSelect = _ref2.onSelect,
      _ref2$menus = _ref2.menus,
      menus = _ref2$menus === void 0 ? [] : _ref2$menus,
      children = _ref2.children;

  var _useContext2 = useContext(ConfigProvider.ConfigContext),
      getPrefixCls = _useContext2.getPrefixCls;

  var className = getPrefixCls('pro-table-dropdown');

  var menu = _jsx(Menu, {
    onClick: function onClick(params) {
      onSelect === null || onSelect === void 0 ? void 0 : onSelect(params.key);
    },
    items: menus.map(function (_ref3) {
      var key = _ref3.key,
          name = _ref3.name,
          rest = _objectWithoutProperties(_ref3, _excluded);

      return _objectSpread(_objectSpread({
        key: key
      }, rest), {}, {
        title: rest.title,
        label: name
      });
    })
  });

  return _jsx(Dropdown, {
    overlay: menu,
    className: classnames(className, propsClassName),
    children: _jsx("a", {
      style: style,
      children: children || _jsx(EllipsisOutlined, {})
    })
  });
};

TableDropdown.Button = DropdownButton;
export default TableDropdown;